AVCastManager
| Kind of class: | public class |
|---|---|
| Package: | com.smartfoxserver.redbox |
| Inherits from: | EventDispatcher |
| Version: | 1.0.0 |
| Author: | The gotoAndPlay() Team http://www.smartfoxserver.com http://www.gotoandplay.it |
| Classpath: | com.smartfoxserver.redbox.AVCastManager |
| File last modified: | Thursday, 06 March 2008, 10:43:17 |
SmartFoxServer's RedBox Audio/Video Broadcast Manager.
This class is responsible for managing audio/video live casts inside the room joined by the user, making it possible to create live web events or a/v conferences.
The AVCastManager handles the live cast publishing/playing to/from the Red5 server.
Unlike the other RedBox classes, the AVCastManager works on a room basis to leverage the access control and moderation features of SmartFoxServer rooms.
NOTE: in the provided examples,
This class is responsible for managing audio/video live casts inside the room joined by the user, making it possible to create live web events or a/v conferences.
The AVCastManager handles the live cast publishing/playing to/from the Red5 server.
Unlike the other RedBox classes, the AVCastManager works on a room basis to leverage the access control and moderation features of SmartFoxServer rooms.
NOTE: in the provided examples,
avCastMan always indicates an AVCastManager instance.Usage:
- The most common usages for the AVCastManager class are video conference applications and live webcast applications (for example live online seminars).
Video conference
In this kind of application, each user publishes his own live stream and subscribes the streams coming from the other users in the same room (in the SmartFoxServer meaning). The following workflow is suggested.- The current user joins the room where the video conference takes place.
- The list of currently available streams (or "live casts") is retrieved by means of the getAvailableCasts method (in case the conference is already in progress).
Calling this method also enables the reception of the RedBoxCastEvent.onLiveCastPublished and RedBoxCastEvent.onLiveCastUnpublished events which notify that another user started or stopped his own stream. - Each live cast is subscribed by means of the subscribeLiveCast method and a Video object is displayed on the stage to attach the stream to.
When a live cast is published (a new user joins the conference) or stopped (a user leaves the conference), a notification is received by means of the above mentioned events: the stream is subscribed / unsubscribed and displayed on / removed from the stage. - The a/v stream for the current user is published by means of the publishLiveCast method and an additional Video object showing the user own camera stream is added on the stage; when the current user publishes his own stream, the other users receive the above mentioned events.
- To make the current user leave the conference, the unpublishLiveCast method is called. Also changing SmartFoxServer room causes the user to leave the conference and the other users to be notified.
Live webcast
In this kind of application, a single user publishes his own live stream and all the other users in the same room subscribe it. The following workflow is suggested.- The publisher joins the room where the live webcast takes place.
- The a/v stream for the user is published by means of the publishLiveCast method and a Video object showing the user own camera stream is added on the stage; when the current user publishes his own stream, the other users already in the room receive the RedBoxCastEvent.onLiveCastPublished event and the stream can be subscribed (see step 4).
- The webcast spectators join the room and retrieve the list of available streams (one item only if the publisher is already streaming, otherwise the list will be empty).
- If the live webcast is already started, it can be subscribed by means of the subscribeLiveCast method; otherwise the RedBoxCastEvent.onLiveCastPublished event must be waited for before calling this method.
- On all the subscribers clients a Video object is displayed on the stage to attach the stream to.
Events broadcasted to listeners:
- RedBoxCastEvent with type:
onAVConnectionInited- Dispatched when the connection to Red5 server has been established.
- RedBoxCastEvent with type:
onAVConnectionError- Dispatched when the connection to Red5 server can't be established.
- RedBoxCastEvent with type:
onLiveCastPublished- Dispatched when a user in the current room published his own live stream.
- RedBoxCastEvent with type:
onLiveCastUnpublished- Dispatched when a user in the current room stops his own live stream.
Summary
Constructor
- AVCastManager (sfs:SmartFoxClient, red5Ip:String, debug:Boolean = false)
- AVCastManager contructor.
Instance properties
- isConnected : Boolean
- The status of the connection to the Red5 server.
Instance methods
- initAVConnection : void
- Initialize the audio/video connection.
- destroy : void
- Destroy the AVCastManager instance.
- getAvailableCasts : Array
- Retrieve the list of available live broadcasts for the current room.
- stopPublishNotification : void
- Stop receiving live cast published/unpublished events.
- subscribeLiveCast (castId:String) : NetStream
- Subscribe a live cast to receive its audio/video stream.
- unsubscribeLiveCast (castId:String) : void
- Unsubscribe a live cast to stop receiving its audio/video stream.
- unsubscribeAllLiveCasts : void
- Unsubscribe all currently subscribed live casts.
- publishLiveCast (enableCamera:Boolean = true, enableMicrophone:Boolean = true) : NetStream
- Start broadcasting the current user's live stream.
- unpublishLiveCast : void
- Stop broadcasting the current user's live stream.
Constructor
AVCastManager
public function AVCastManager (
sfs:SmartFoxClient,
red5Ip:String,
debug:Boolean = false)
AVCastManager contructor.
Parameters:
sfs :
the SmartFoxClient instance.
red5Ip:
the Red5 server IP address.
debug :
turn on the debug messages (optional, default is
false).Throws:
- MyUserPropsNotSetException if the SmartFoxClient.myUserId or SmartFoxClient.myUserName properties are not set.
Example:
- The following example shows how to instantiate the AVCastManager class.
var smartFox:SmartFoxServer = new SmartFoxServer(true) var red5IpAddress:String = "127.0.0.1" var avCastMan:AVCastManager = new AVCastManager(smartFox, red5IpAddress)
See also:
Instance properties
isConnected
public isConnected:Boolean
(read)
The status of the connection to the Red5 server.
If
If
true, the connection to Red5 is currently available. Instance methods
destroy
public function destroy (
) : void
Destroy the AVCastManager instance.
Calling this method causes the interruption of all the playing streams (if any) and the disconnection from Red5.
This method should always be called before deleting the AVCastManager instance.
Calling this method causes the interruption of all the playing streams (if any) and the disconnection from Red5.
This method should always be called before deleting the AVCastManager instance.
Example:
- The following example shows how to destroy the AVCastManager instance.
avCastMan.destroy() avCastMan = null
getAvailableCasts
public function getAvailableCasts (
) : Array
Retrieve the list of available live broadcasts for the current room.
The list is populated by the AVCastManager class as soon as it is instantiated and each time a new room is joined.
When this method is called, the RedBoxCastEvent.onLiveCastPublished and RedBoxCastEvent.onLiveCastUnpublished events dispatching is enabled, in order to be notified when users in the current room start/stop streaming.
In order to turn off events notification, the stopPublishNotification method should be called.
The list is populated by the AVCastManager class as soon as it is instantiated and each time a new room is joined.
When this method is called, the RedBoxCastEvent.onLiveCastPublished and RedBoxCastEvent.onLiveCastUnpublished events dispatching is enabled, in order to be notified when users in the current room start/stop streaming.
In order to turn off events notification, the stopPublishNotification method should be called.
Returns:
- An array of LiveCast objects.
Example:
- The following example shows how to loop through the list of live casts available for the current room.
for each (var liveCast:LiveCast in avCastMan.getAvailableCasts()) { // Subscribe live cast var stream:NetStream = avCastMan.subscribeLiveCast(liveCast.id) // Display a/v stream on stage ... }
See also:
initAVConnection
public function initAVConnection (
) : void
Initialize the audio/video connection.
Calling this method causes the connection to Red5 to be established and the RedBoxCastEvent.onAVConnectionInited event to be fired in response.
If the connection can't be established, the RedBoxCastEvent.onAVConnectionError event is fired in response.
NOTE: this method is called automatically when the AVCastManager is instantiated.
Calling this method causes the connection to Red5 to be established and the RedBoxCastEvent.onAVConnectionInited event to be fired in response.
If the connection can't be established, the RedBoxCastEvent.onAVConnectionError event is fired in response.
NOTE: this method is called automatically when the AVCastManager is instantiated.
Events broadcasted to listeners:
- RedBoxCastEvent with type:
onAVConnectionInited- Dispatched when the connection to Red5 server has been established.
- RedBoxCastEvent with type:
onAVConnectionError- Dispatched when the connection to Red5 server can't be established.
Example:
- The following example shows how to initialize the Red5 connection for the AVCastManager instance.
avCastMan.initAVConnection()
publishLiveCast
public function publishLiveCast (
enableCamera:Boolean = true,
enableMicrophone:Boolean = true) : NetStream
Start broadcasting the current user's live stream.
Calling this method causes the RedBoxCastEvent.onLiveCastPublished event to be fired on the other users clients.
Audio and video recording mode/quality should be set before calling this method. In order to alter these settings, please refer to the flash.media.Microphone and flash.media.Camera classes documentation.
Calling this method causes the RedBoxCastEvent.onLiveCastPublished event to be fired on the other users clients.
Audio and video recording mode/quality should be set before calling this method. In order to alter these settings, please refer to the flash.media.Microphone and flash.media.Camera classes documentation.
Parameters:
enableCamera :
enable video live streaming; default value is
true.enableMicrophone:
enable audio live streaming; default value is
true.Returns:
- The flash.net.NetStream object representing the user's outgoing stream.
Events broadcasted to listeners:
- RedBoxCastEvent with type:
onLiveCastPublished- Dispatched when a user in the current room published his own live stream.
Throws:
- NoAVConnectionException if the connection to Red5 is not available.
- InvalidParamsException if both enableCamera and enableMicrophone parameters are set to
false.
Example:
- The following example shows how to publish the current user's live stream.
avCastman.publishLiveCast(true, true)
See also:
- unpublishLiveCast
- RedBoxCastEvent.onLiveCastPublished
- NoAVConnectionException
- InvalidParamsException
- flash.media.Camera
- flash.media.Microphone
- flash.net.NetStream
stopPublishNotification
public function stopPublishNotification (
) : void
Stop receiving live cast published/unpublished events.
See also:
subscribeLiveCast
public function subscribeLiveCast (
castId:String) : NetStream
Subscribe a live cast to receive its audio/video stream.
Parameters:
castId:
(String) the id of the LiveCast object to be subscribed.
Returns:
- A flash.net.NetStream object.
Throws:
- NoAVConnectionException if the connection to Red5 is not available.
Example:
- The following example shows how to subscribe a live cast when a publishing notification is received.
avCastMan.addEventListener(RedBoxCastEvent.onLiveCastPublished, onLiveCastPublished) // A user publishes his own live cast... function onLiveCastPublished(evt:RedBoxCastEvent):void { var liveCast:LiveCast = evt.params.liveCast // Subscribe live cast var stream:NetStream = avCastMan.subscribeLiveCast(liveCast.id) // Display a/v stream on stage ... }
See also:
- unsubscribeLiveCast
- NoAVConnectionException
- flash.net.NetStream
unpublishLiveCast
public function unpublishLiveCast (
) : void
Stop broadcasting the current user's live stream.
Calling this method causes the RedBoxCastEvent.onLiveCastUnpublished event to be fired on the other users clients.
Calling this method causes the RedBoxCastEvent.onLiveCastUnpublished event to be fired on the other users clients.
Events broadcasted to listeners:
- RedBoxCastEvent with type:
onLiveCastUnpublished- Dispatched when a user in the current room stops his own live stream.
Example:
- The following example shows how to unpublish a live cast.
avCastMan.unpublishLiveCast()
unsubscribeAllLiveCasts
public function unsubscribeAllLiveCasts (
) : void
Unsubscribe all currently subscribed live casts.
See also:
unsubscribeLiveCast
public function unsubscribeLiveCast (
castId:String) : void
Unsubscribe a live cast to stop receiving its audio/video stream.
NOTE: when a user stops his own stream or leaves the current room / disconnects from SmartFoxServer while his stream is in progress, the AVCastManager class automatically unsubscribes the live cast before dispatching the RedBoxCastEvent.onLiveCastUnpublished event.
NOTE: when a user stops his own stream or leaves the current room / disconnects from SmartFoxServer while his stream is in progress, the AVCastManager class automatically unsubscribes the live cast before dispatching the RedBoxCastEvent.onLiveCastUnpublished event.
Parameters:
castId:
(String) the id of the LiveCast object to be unsubscribed.
Example:
- The following example shows how to unsubscribe a live cast.
avCastMan.unsubscribeLiveCast(liveCast.id)
See also: